<template>
  <el-card class="content">
    <el-form inline>
      <el-form-item label="事故点">
        <el-input
          placeholder="请输入巡查点"
          size="mini"
          v-model="query.position"
          clearable
        >
        </el-input>
      </el-form-item>
      <el-form-item label="事故类型">
        <el-select
          v-model="query.accidentTypeId"
          placeholder="请选择事故类型"
          size="mini"
          clearable
        >
          <el-option
            v-for="item in accidentTypeList"
            :key="item.id"
            :label="item.accidentTypeName"
            :value="item.id"
          ></el-option> </el-select
      ></el-form-item>
      <el-form-item label="开始时间">
        <el-date-picker
          type="datetime"
          placeholder="选择开始日期"
          default-time="00:00:00"
          size="mini"
          v-model="startTime"
          :picker-options="pickerOptions0"
          clearable
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker
          type="datetime"
          placeholder="选择结束日期"
          default-time="00:00:00"
          size="mini"
          v-model="endTime"
          :picker-options="pickerOptions0"
          clearable
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="getAccidentReportByPage"
          >查询</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      :data="accidentReportList"
      size="small"
      :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }"
      class="el-table-box"
      stripe
    >
      <el-table-column label="事故点" prop="position"></el-table-column>
      <el-table-column label="巡查日期" prop="reportTime"></el-table-column>
      <el-table-column label="巡查人" prop="userName"></el-table-column>
      <el-table-column
        label="事故类型"
        prop="accidentTypeName"
      ></el-table-column>
      <el-table-column
        label="事故内容"
        prop="accidentContent"
      ></el-table-column>
    </el-table>
    <el-row type="flex" justify="end">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.page"
        :page-sizes="[10, 15]"
        :page-size="query.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-row>
  </el-card>
</template>

<script>
import { getAccidentReportByPage, getAccidentTypeList } from "../../api/help";
import moment from "moment";
export default {
  name: "WarningReception",
  props: {
    node: Object,
  },
  data() {
    return {
      endTime: moment().format("YYYY-MM-DD HH:mm:ss"),
      startTime: moment().subtract(1, "months").format("YYYY-MM-DD 00:00:00"),
      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() > Date.now(); //如果没有后面的-8.64e6就是不可以选择今天的
        },
      },
      query: {
        page: 1,
        pagesize: 10,
        position: "",
        accidentTypeId: null,
      },
      total: null,
      accidentReportList: [],
      accidentTypeList: [],
    };
  },
  mounted() {
    this.getAccidentTypeList();
    this.getAccidentReportByPage();
  },
  methods: {
    async getAccidentReportByPage() {
      let queryData = {
        startTime: moment(this.startTime).format("YYYY-MM-DD 00:00:00"),
        endTime: moment(this.endTime).format("YYYY-MM-DD HH:mm:ss"),
      };
      const res = await getAccidentReportByPage({
        startTime: queryData.startTime,
        endTime: queryData.endTime,
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        position: this.query.position,
        accidentTypeId: this.query.accidentTypeId,
      });
      if (res.resultCode == "200") {
        this.accidentReportList = res.parameter.list;
        this.total = res.parameter.total;
      } else {
        this.$message({
          message: "暂无数据",
          offset: 400,
          duration: 1000,
        });
        this.accidentReportList = [];
        this.total = 0;
      }
    },
    // 监听 pagesize 改变的事件
    handleSizeChange(val) {
      this.query.pagesize = val;
      this.getAccidentReportByPage();
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(val) {
      this.query.page = val;
      this.getAccidentReportByPage();
    },
    async getAccidentTypeList() {
      const res = await getAccidentTypeList();
      this.accidentTypeList = res.parameter;
    },
  },
};
</script>

<style scoped>
.content {
  margin-left: 0.08rem;
  font-size: 0.07rem;
  height: 90vh;
}
.el-table-box {
  margin-bottom: 0.1rem;
  margin-top: 0.1rem;
  display: block;
  height: 70vh;
  overflow: auto;
}
.el-table::before {
  z-index: inherit;
}
table {
  text-align: center;
}
</style>